/**
 * 
 */
package nepomuk.sandbox;

import org.ontoware.aifbcommons.collection.ClosableIterator;
import org.ontoware.rdf2go.RDF2Go;
import org.ontoware.rdf2go.model.Model;
import org.ontoware.rdf2go.model.Statement;
import org.ontoware.rdf2go.model.node.URI;
import org.ontoware.rdf2go.model.node.Variable;

/**
 * @author kotelnikov
 */
public class RDFExample {

    public static void main(String[] args) {
        new RDFExample().run();
    }

    /**
     * 
     */
    public RDFExample() {
    }

    public void run() {
        // getting model
        Model model = RDF2Go.getModelFactory().createModel();
        model.open();
        try {
            // creating URIs
            URI max = model.createURI("http://xam.de/foaf.rdf.xml#i");
            URI currentProject = model
                .createURI("http://xmlns.com/foaf/0.1/#term_currentProject");
            URI name = model.createURI("http://xmlns.com/foaf/0.1/#term_name");
            URI semweb4j = model.createURI("http://semweb4j.org");

            // adding a statement to the model
            model.addStatement(max, currentProject, semweb4j);
            model.addStatement(max, name, "Max Völkel");

            // dumping model to the screen
            model.dump();

            // query model for all names of max
            ClosableIterator<Statement> cursor = model.findStatements(
                max,
                name,
                Variable.ANY);
            try {
                while (cursor.hasNext()) {
                    Statement stmt = cursor.next();
                    System.out.println(stmt.getObject());
                }
            } finally {
                cursor.close();
            }
        } finally {
            model.close();
        }
    }
}
